﻿using CommonLib;
using CommonLib.Util;
using UnityEngine;
using UnityEngine.UI;

public class RolePlusEffectItem : EffectItemBase, IInitByInstruction
{
	[SerializeField]
	int actionScore = 10;
	[SerializeField]
	string applyImage = "";
	[SerializeField]
	Image imageUI;
	private void Awake()
	{
		imageUI = gameObject.GetComponentIfMissing<Image>();
	}

	protected override void EffectWithPlayer(RoleCtrl ctrl)
	{
		ctrl.RoleEntity.CurrentScore += actionScore;
	}

	public void SetScore(int newScore)
	{
		if(newScore > 0)
		{
			this.IsPositive = true;
		}
		else
		{
			this.IsPositive = false;
		}
		actionScore = newScore;
	}

	public void Init(BPInstruction instruction)
	{
		this.actionScore = int.Parse(instruction.Params[2]);
		this.applyImage = instruction.Params[3];
		imageUI.sprite = GameResourceLoader.Instance.LoadFromResource<Sprite>(GameResource.TextureResMgr.GetPath(AppPath.Resource, applyImage));
		IsPositive = this.actionScore > 0 ? true : false;
	}
}
